using NUnit.Framework;
using Nuwanda.TfsSpotlight.Shell.Proxies;
using Nuwanda.TfsSpotlight.Shell.Proxies.Interfaces;
using Rhino.Mocks;

namespace Nuwanda.TfsSpotlight.Shell.Tests.Proxies
{
    [TestFixture]
    public class TabStripItemTests
    {
        private MockRepository _mocks;
        private ITabPresenter _tabPresenterMock;

        private TabStripItem _testSubject;

        [SetUp]
        public void SetUp()
        {
            this._mocks = new MockRepository();
            this._tabPresenterMock = this._mocks.StrictMock<ITabPresenter>();

            this._testSubject = new TabStripItem();
        }

        [Test]
        public void WhenAskedTo_SetCaption_ShouldSetCaption()
        {
            var caption = "CAPTION";

            this._testSubject.SetCaption(caption);

            Assert.AreEqual(caption, this._testSubject.Caption);
        }

        [Test]
        public void WhenAskedTo_RefreshCaption_And_PresenterIsDirty_Should_SetCaptionWithIsDirtyMark()
        {
            var caption = "CAPTION";

            using (this._mocks.Record())
            {
                Expect.Call(this._tabPresenterMock.IsDirty).Return(true);
                Expect.Call(this._tabPresenterMock.GetCaption()).Return(caption);
            }

            using (this._mocks.Playback())
            {
                this._testSubject.Presenter = this._tabPresenterMock;
                this._testSubject.RefreshCaption();
                Assert.AreEqual(caption + TabStripItem.MODIFIED_TAB_CONTENTS_MARK, this._testSubject.Caption);
            }
        }

        [Test]
        public void WhenAskedTo_RefreshCaption_And_PresenterIsNOTDirty_Should_SetCaptionWithoutIsDirtyMark()
        {
            var caption = "CAPTION";

            using (this._mocks.Record())
            {
                Expect.Call(this._tabPresenterMock.IsDirty).Return(false);
                Expect.Call(this._tabPresenterMock.GetCaption()).Return(caption);
            }

            using (this._mocks.Playback())
            {
                this._testSubject.Presenter = this._tabPresenterMock;
                this._testSubject.RefreshCaption();
                Assert.AreEqual(caption, this._testSubject.Caption);
            }
        }
    }
}